package com.ele.Servlet;

import com.ele.Pojo.Business;
import com.ele.Service.impl.BusinessServiceImpl;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/AllBusiness")
public class BusinessServletAll extends HttpServlet {
    //对象service
    BusinessServiceImpl businessService = new BusinessServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("请求所有商家");
        //获得集合
        List<Business> businesses = businessService.getAllBusiness();
        Gson gson =new Gson();
        String json =gson.toJson(businesses);
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(json);
    }
}
